import java.util.Stack;

/**
 * Creat with IntelliJ IDEA
 * Description:
 * User:WZW
 * Date:2022-01-28
 * Time:23:41
 */

class Solution {
    public int evalRPN(String[] tokens) {
        if(tokens == null)
        {
            return 0;
        }
        Stack<Integer> stack = new Stack<>();
        int i = 0;
        stack.push(Integer.parseInt(tokens[i++]));
        while(i<tokens.length)
        {
            if(tokens[i].equals("+")) {
                Integer ret = stack.pop();
                ret = stack.pop()+ret;
                stack.push(ret);
            }
            else if (tokens[i].equals("-")) {
                Integer ret = stack.pop();
                ret = stack.pop()-ret;
                stack.push(ret);
            }
            else if (tokens[i].equals("*")) {
                Integer ret = stack.pop();
                ret = stack.pop()*ret;
                stack.push(ret);
            }
            else if (tokens[i].equals("/")) {
                Integer ret = stack.pop();
                ret = stack.pop()/ret;
                stack.push(ret);
            }
            else
            {
                stack.push(Integer.parseInt(tokens[i]));
            }
            i++;
        }
        return stack.pop();
    }
}

public class stack_homework {

}
